﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Diagrams;

namespace Microsoft.Samples.DslTools.ConfigurationSectionDesigner
{
    // The three methods in this file are used to provide the "custom source" for the ElementPropertyHasTypeConnector.
    // The Element properties inside Configuration Elements refer to other Configuration Elements in the diagram.
    // These Element properties don't have their own shape (they are shown in a Compartment Decorator) so they cannot
    // have a standard connector from one shape to the other. The ElementPropertyHasTypeConnector is defined as having
    // a "Custom Source", for which the following methods provide the implementation code.

    public partial class ConfigurationSectionDesignerDiagram
    {
        private NodeShape GetSourceShapeForElementPropertyHasTypeConnector(ElementPropertyHasTypeConnector connector)
        {
            // Jump from the Element Property to its parent shape, i.e. the Configuration Element that contains it.
            // This will make the connection start at shape of the "owning" Configuration Element.
            return (NodeShape)connector.ParentShape;
        }

        private ModelElement GetSourceRolePlayerForLinkMappedByElementPropertyHasTypeConnector(ElementPropertyHasTypeConnector connector)
        {
            // Likewise, the source role player is the "owning" Configuration Element.
            return connector.ParentShape.ModelElement;
        }
    }

    internal partial class FixUpDiagram
    {
        private ModelElement GetParentForElementPropertyHasType(ElementPropertyHasType childLink)
        {
            // Jump from the link to the Element property and up to its "owning" Configuration Element.
            return childLink.ElementProperty.ConfigurationElement;
        }
    }
}